package com.example.freeze;

import java.util.ArrayList;
import java.util.List;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;



public class InsertedItemManager {
	public static final String PACKAGE_NAME = "com.example.freeze";
	public static final String databaseFile = "/data/data/" + PACKAGE_NAME
			+ "/recipe.db";

	
	
	
	public static List<InsertedItem> getUserList(){
		List<InsertedItem> returnList = new ArrayList<InsertedItem>();
		SQLiteDatabase db = SQLiteDatabase.openDatabase(databaseFile,null,SQLiteDatabase.OPEN_READWRITE);
		Cursor cursor = db.rawQuery("SELECT * FROM item", null);
		while(cursor.moveToNext()){
			InsertedItem item = new InsertedItem();
			item.setItem_id(cursor.getInt(cursor.getColumnIndex("item_id")));
			item.setFood_name(cursor.getString(cursor.getColumnIndex("food_name")));
			item.setInsert_date(cursor.getInt(cursor.getColumnIndex("insert_date")));
			item.setEx_date(cursor.getInt(cursor.getColumnIndex("ex_date")));
			item.setNum(cursor.getInt(cursor.getColumnIndex("num")));
			returnList.add(item);
		}
		db.close();
		return returnList;
	}
	
	
	public static void insertUser(InsertedItem i){
		SQLiteDatabase db = SQLiteDatabase.openDatabase(databaseFile,null,SQLiteDatabase.OPEN_READWRITE);
		db.execSQL("INSERT INTO item(food_name,insert_date,ex_date,num) VALUES('"
		+i.getFood_name()+"',"+i.getInsert_date()+","+i.getEx_date()+","+i.getNum()+")");
		db.close();
	}


	public static void deleteUser(InsertedItem i){
		SQLiteDatabase db = SQLiteDatabase.openDatabase(databaseFile,null,SQLiteDatabase.OPEN_READWRITE);
		db.execSQL("DELETE FROM item WHERE "+i.getItem_id());
		db.close();
	}

	
}
